using System;
using System.Data;

namespace MetaObjects.Core
{
	public class DataColumnAttribute : Attribute
	{
		public string InternalName { get; private set; }
		public Action<DataRow, object> SetField { get; private set; }
		public Func<DataRow, object> GetField { get; private set; }

		public DataColumnAttribute(string name)
		{
			InternalName = name;
			GetField = GetFieldValue;
			SetField = SetFieldValue;
		}

		public DataColumnAttribute(string name, Action<DataRow, object> setField, Func<DataRow, object> getField)
		{
			InternalName = name;
			SetField = setField;
			GetField = getField;
		}

		protected virtual object GetFieldValue(DataRow row)
		{
			return row[InternalName];
		}

		protected virtual void SetFieldValue(DataRow row, object value)
		{
			row[InternalName] = value;
		}
	}
}